# Overview

## Plugin hooks

Rspack plugin hooks are similar to the webpack plugin, mainly including the following categories:

- [Compiler hooks](/api/plugin-api/compiler-hooks): Intervene at various stages of the entire build process
- [Compilation hooks](/api/plugin-api/compilation-hooks): Intervene at various stages of a single build
- [RuntimePlugin hooks](/api/plugin-api/runtime-plugin-hooks): Intervene in the generation of runtime code
- [NormalModuleFactory hooks](/api/plugin-api/normal-module-factory-hooks): Intervene at various stages of the module creation process
- [Stats hooks](/api/plugin-api/stats-hooks): Intervene in the generation of stats

## Compatibility status

Rspack is committed to being compatible with the plugins within the webpack ecosystem. We ensure that Rspack is as compatible as possible with the webpack plugin API, allowing more existing webpack plugins to be directly used in Rspack.

We have already made most of the webpack plugin APIs compatible. You can visit [this page](https://github.com/orgs/web-infra-dev/projects/9) to learn about the current compatibility status of webpack plugin APIs.

## Writing plugins compatible with Rspack and webpack

In most cases, you don't need to do any extra work to make a webpack plugin run correctly in Rspack. However, you should avoid directly importing classes or methods from the webpack package. Instead, retrieve these classes or methods from the `compiler` object within your plugin.

```js
export class Plugin {
  apply(compiler) {
    const {
      DefinePlugin, // Retrieve plugin
      NormalModule,
      sources: { RawSource }, // Retrieve class
    } = compiler.webpack;
  }
}
```

Although Rspack strives to be compatible with webpack's plugin API, you may still encounter some subtle differences between Rspack and webpack's plugin APIs. To determine whether your plugin is running in webpack or Rspack, you can check the `compiler.rspack` property:

```js
export class Plugin {
  apply(compiler) {
    if (compiler.rspack) {
      // Logic for running in Rspack
    } else {
      // Logic for running in webpack
    }
  }
}
```
